//移除链表元素
//输入：head = [1,2,6,3,4,5,6], val = 6
//输出：[1,2,3,4,5]
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution1 {
    public ListNode removeElements(ListNode head, int val) {
       if(head == null){
        return head;
       }
       ListNode prev = head;
       ListNode cur = head.next;
       while (cur != null){
            if(cur.val == val){
                prev.next = cur.next;
                cur = cur.next;
            }else{
                prev = cur;
                cur = cur.next;
            }
       }
       if(head.val == val){
          head = head.next;
       }
       return head;
    }
}